const bcrypt = require('bcryptjs')

// 对密码进行加密
const hashPassword = (password) => {
  return bcrypt.hash(password, 10)
}

// 验证密码
const checkPassword = async (password, hashedPassword) => {
  try {
    const isMatch = await bcrypt.compare(password, hashedPassword)
    return isMatch
  } catch (error) {
    console.error('密码匹配失败', error);
    throw new Error('密码错误')
  }
}

module.exports = {
  hashPassword,
  checkPassword
}